UiHelper.label = UiHelper.frame:extend()
local fam = {family = "fonts.ttf", size = 8 * 0.001, flag = 0, align = TEXT_ALIGN_LEFT}
local labelType = {}
labelType["TEXT"] = {fdfType = "TEXT", fdfName = ""}
--labelType["TEXTBUTTON"]={fdfType="TEXTBUTTON",fdfName="StandardBorderedButtonTemplate"}
--labelType["GLUEBUTTON"]={fdfType="GLUEBUTTON",fdfName="StandardButtonTemplate"}

--- 创建label
---@param frameId number
---@param relation number-相对节点ID(def:hdzui.origin.game())
---@param align number-integer-参考blizzard:^FRAME_ALIGN FRAME_ALIGN_CENTER
---@param alignRelation number以-align-> alignParent 对齐 FRAME_ALIGN_CENTER
---@param x number-锚点X
---@param y number-锚点Y
---@param fdfName string-frame名称
---@param parent number-父节点ID(def:hdzui.origin.game())
---@param tag string-自定义tag名称(def:cache.tagIdx)
---@param id number-integer(def:0)
---@param w number-宽
---@param h number-高
---@param show bool-显示 隐藏
---@param text string-文本
---@param TextAlign string-TEXT_ALIGN_CENTER = 2 -- 文本对齐中 TEXT_ALIGN_LEFT = 10 -- 文本对齐左 TEXT_ALIGN_RIGHT = 34 -- 文本对齐右
---fdfType TEXTBUTTON 文本按钮
---TEXT_ALIGN_CENTER = 2 -- 文本对齐中 TEXT_ALIGN_LEFT = 10 -- 文本对齐左 TEXT_ALIGN_RIGHT = 34 -- 文本对齐右
---style-{fdfName="fdfName",family="fonts.ttf",size=8 * 0.001,flag=0,align=TEXT_ALIGN_CENTER}
function UiHelper.label:new(args)
    args = args or {}
    if args.fdfType == nil or labelType[args.fdfType] == nil then
        args.fdfType = "TEXT"
    end

    args.fdfType = labelType[args.fdfType].fdfType
    args.fdfName = labelType[args.fdfType].fdfName
    args.text = args.text or "label文本"
    args.align = args.align or FRAME_ALIGN_CENTER
    args.alignRelation = args.alignRelation or FRAME_ALIGN_CENTER
    args.x = args.x or 0
    args.y = args.y or 0
    args.w = args.w or 0
    args.h = args.h or 0.01

    self.click = args.click
    self.enter = args.enter
    self.leave = args.leave
    self.doubleClick = args.doubleClick
    self.parent = args.parent
    self.style = args.style or fam

    self.frame = UiHelper.frame(args)
    self.frameId = self.frame.frameId
    self.text = args.text

    self.relation = args.relation

    self.align = args.align
    self.alignRelation = args.alignRelation
    self.x = args.x
    self.y = args.y
    self.w = args.w
    self.h = args.h
    self.show = args.show
    self.TextAlign = args.TextAlign

    self:dftext(self.text)

    self:dfsetStyle(nil, nil, nil)
    if self.style ~= nil and self.style.align ~= nil then
        self:dfsetTextAlignment(self.style.align)
        self:dfsetStyle(self.style.family, self.style.size, 0)
    end

    if self.TextAlign ~= nil then
        self:dfsetTextAlignment(self.TextAlign)
    end

    return self
end

---清空frame所有锚点
function UiHelper.label:dfClearAllPoints()
    self.frame:dfClearAllPoints()
    return self
end

---设置文本
function UiHelper.label:dftext(text)
    self.text = text
    self.frame:dftext(text)
    return self
end

---设置宽高
function UiHelper.label:dfsize(w, h)
    self.frame:dfsize(w, h)
    return self
end

---设置锚点 相对位置{point,relativeFrame,relativePoint}
function UiHelper.label:dfpoint(x, y, point, relativeFrame, relativePoint)
    self.frame:dfpoint(x, y, point, relativeFrame, relativePoint)
    return self
end

---偏移
---@param relation number-相对节点ID(def:hdzui.origin.game())
---@param x number-锚点X
---@param y number-锚点Y
function UiHelper.label:dfpointp(x, y, relation, align, alignRelation)
    self.frame:dfpointp(x, y, relation, align, alignRelation)
    return self
end

---设置绝对位置
function UiHelper.label:dfAbsolutePoint(x, y, point)
    self.frame:dfAbsolutePoint(x, y, point)
    return self
end

---设置frame文本 支持EditBox, TextFrame, TextArea, SimpleFontString、GlueEditBoxWar3、SlashChatBox、TimerTextFrame、TextButtonFrame、GlueTextButton
function UiHelper.label:dftext(text)
    self.frame:dftext(text)
    return self
end

--- 设置字体 设置 frame 的字体为 font, 大小 height, flag flag 支持EditBox、SimpleFontString、SimpleMessageFrame以及非SimpleFrame类型的例如TEXT，flag作用未知
function UiHelper.label:dfsetStyle(family, size, flag)
    self.frame:dfsetStyle(family, size, flag)
    return self
end

---设置frame对齐方式 支持TextFrame、SimpleFontString、SimpleMessageFrame
---TEXT_ALIGN_CENTER = 2 -- 文本对齐中 TEXT_ALIGN_LEFT = 10 -- 文本对齐左 TEXT_ALIGN_RIGHT = 34 -- 文本对齐右
function UiHelper.label:dfsetTextAlignment(align)
    self.frame:dfsetTextAlignment(align)
    return self
end

---显示
function UiHelper.label:dfshow(show)
    if show == nil then
        show = true
    end

    self.frame:dfshow(show)
    return self
end

---隐藏
function UiHelper.label:dfhide()
    self.frame:dfhide()
    return self
end


---点击事件
function UiHelper.label:CLICK(align)
    self.frame:CLICK(align)
    return self
end
---悬浮事件
function UiHelper.label:ENTER(align)
    self.frame:ENTER(align)
    return self
end
---离开事件
function UiHelper.label:LEAVE(align)
    self.frame:LEAVE(align)
    return self
end
---释放事件
function UiHelper.label:RELEASE(align)
    self.frame:RELEASE(align)
    return self
end
--双击事件
function UiHelper.label:DOUBLE_CLICK(align)
    self.frame:DOUBLE_CLICK(align)
    return self
end